package com.yh.correct.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.yh.correct.model.ResultData;
import com.yh.correct.model.SystemMailbox;
import com.yh.correct.service.ISystemMailboxService;

/**
 * 信息站管理控制层
 * 
 * @author 崔赛赛
 */
@RestController
@RequestMapping("/points")
public class SystemMailboxController {
	//实例化信站箱服务层接口
	   @Autowired
       private ISystemMailboxService iSystemMailboxService;
	    /**
		 * 根据id添加信件
	     */

		@RequestMapping("/add")
		public ResultData add(SystemMailbox systemMailbox) {
			
			SystemMailbox ss=new SystemMailbox();
			ss.setTitle("信站箱管理");
			ss.setContent("接到最新通知!");
			ss.setSendTime(new Date());
			ss.setStatus(0);
			ss.setSendId(01);
			ss.setReceiveId(0);
			ResultData rd = new ResultData();
			List<SystemMailbox> mm=new ArrayList<SystemMailbox>();
			mm.add(ss);
			int i=iSystemMailboxService.addSystemMailbox(systemMailbox);
			if(i>0){
			rd.setCode(0);
			rd.setMessage("插入成功！");
			rd.setData(mm);}
			else{
				
				rd.setCode(-1);
				rd.setMessage("插入0！");
				
			}
			return rd;
		}
		/**
		 * 根据id删除信件
	     */
		@RequestMapping("/del")
		public ResultData del(SystemMailbox systemMailbox){
			SystemMailbox ss = new SystemMailbox();
			ResultData rd = new ResultData();
			
			iSystemMailboxService.delSystemMailbox(9);
			rd.setCode(0);
			rd.setMessage("删除成功！");
			return rd;
		}
		/**
		 * 修改信件
	     */
		@RequestMapping("/edit")
		public ResultData edit(SystemMailbox systemMailbox){
			SystemMailbox ss = new SystemMailbox();
			
			ss.setTitle("信站箱管理01");
			ss.setContent("接到最新通知!2222");
			ss.setSendTime(new Date());
			ss.setStatus(0);
			ss.setSendId(01);
			ss.setReceiveId(0);
			ss.setId(2);
			ResultData rd = new ResultData();
			List<SystemMailbox> cc= new ArrayList<SystemMailbox>();
			cc.add(ss);
			iSystemMailboxService.editSystemMailbox(ss);
			rd.setCode(0);
			rd.setMessage("修改成功");
			rd.setData(cc);
			 return rd;
		}
		
		/**
		 * 根据id信件
	     */
		@RequestMapping("/get")
		public ResultData get(SystemMailbox systemMailbox){
			SystemMailbox ss = new SystemMailbox();
			ResultData rd = new ResultData();
			List<SystemMailbox> mm=new ArrayList<SystemMailbox>();
			Integer i = 2;
			SystemMailbox a = iSystemMailboxService.getSystemMailbox(i);
			mm.add(a);
			rd.setCode(0);
			rd.setMessage("查看成功！");
			rd.setData(mm);
			return rd;
			
		}
		/**
		 * 查询所有信件
	     */
		@RequestMapping("/getAll")
		public ResultData getAll(SystemMailbox systemMailbox){
			List<SystemMailbox> o =	iSystemMailboxService.getAllSystemMailbox();
			ResultData rd = new ResultData();
			
			rd.setCode(0);
			rd.setMessage("查询所有信息成功！");
			rd.setData(o);
			return rd;
		}
		}


